package com.att.action;

import com.adkfp.utils.LayuiUtil;
import com.att.bean.HolidaysBean;
import com.att.service.HolidaysService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("holidays")
public class HolidaysAction {

    @Resource(name = "holidaysService")
    private HolidaysService holidaysService;

    /**
     * Description: 转发到页面
     */
    @RequestMapping("holidaysIndex")
    public String holidaysIndex() {
        return "settings/holidays";
    }

    /**
     * Description: 带条件查询节假日记录
     * @param bean
     */
    @RequestMapping("selectAll")
    @ResponseBody
    public Object selectAll(HolidaysBean bean) {
        List<HolidaysBean> list = holidaysService.findByCondition(bean);
        return LayuiUtil.data(Long.valueOf(list.size()), list);
    }

    //新增
    @RequestMapping("insert")
    @ResponseBody
    public String insert(HolidaysBean bean) {
        boolean flag = holidaysService.insert(bean);
        if(flag){
            return "SUCCESS";
        }
        return "ERROR";
    }

    //修改
    @RequestMapping("update")
    @ResponseBody
    public String update(HolidaysBean bean) {
        boolean flag = holidaysService.update(bean);
        if(flag){
            return "SUCCESS";
        }
        return "ERROR";
    }

    //删除
    @RequestMapping("delete")
    @ResponseBody
    public String delete(Integer id) {
        boolean flag = holidaysService.delete(id);
        if(flag){
            return "SUCCESS";
        }
        return "ERROR";
    }
}
